from django.db import models

# Create your models here.

# 首页轮播图
class HomeCarousel(models.Model):
  name = models.CharField(verbose_name='名称', max_length=30, default='')
  link_url = models.TextField(verbose_name='链接', default='')
  is_show = models.BooleanField(verbose_name='是否显示', default='')
  car_img = models.ImageField(verbose_name='图片', upload_to='carousel_img')

  class Meta:
    db_table = 'carousel_img'
    verbose_name_plural = '首页轮播图'

# 一级分类
class PrimaryClassification(models.Model):
  name = models.CharField(verbose_name='名称', max_length=30)
  is_show = models.BooleanField(verbose_name='是否显示', default=False)
  category_ico = models.ImageField(verbose_name='图标', upload_to='first_class_ico')
  created_time = models.DateTimeField(verbose_name='创建时间')
  updated_time = models.DateTimeField(verbose_name='更新时间')

  class Meta:
    verbose_name_plural = '一级分类'
  
  def __str__(self):
    return self.name

# 二级分类
class SecondaryClassification(models.Model):
  name = models.CharField(verbose_name='名称', max_length=30)
  is_show = models.BooleanField(verbose_name='是否显示', default=False)
  upper_level = models.ForeignKey(PrimaryClassification, verbose_name='上级分类', related_name='class_name')
  created_time = models.DateTimeField(verbose_name='创建时间')
  updated_time = models.DateTimeField(verbose_name='更新时间')

  class Meta:
    verbose_name_plural = '二级分类'

# 热门搜索
class HotSearchKeyword(models.Model):
  name = models.CharField(verbose_name='名称', max_length=50)
  is_show = models.BooleanField(verbose_name='是否显示', default=True)

  class Meta:
    verbose_name_plural = '热门搜索'
  
  def __str__(self):
    return self.name
